﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Admin_login : System.Web.UI.Page
{
    myDataSetTableAdapters.AccountsTableAdapter accAdapter = new myDataSetTableAdapters.AccountsTableAdapter();
    protected void Page_Load(object sender, EventArgs e)
    {
        Session["id"] = null;
        Session["userName"] = null;
        Session["login"] = null;
    }

    protected bool checkEmpty()
    {
        bool status = true;
        if (txtUsername.Text.Trim() == "" || txtPass.Text.Trim() == "")
        {
            lblError.Text = "Empty!";
            Panel1.Visible = true;
            status = false;
        }
        else
        {
            Panel1.Visible = false;
        }
        return status;
    }
    protected void cmdSignin_Click(object sender, EventArgs e)
    {
        if (checkEmpty())
        {
            myDataSet.AccountsDataTable accTable = accAdapter.GetDataAdminByUserPassType(txtUsername.Text.Trim(), txtPass.Text.Trim());
            if (accTable.Rows.Count != 0)
            {
                Session["id"] = accTable.Rows[0]["id"].ToString();
                Session["userName"] = accTable.Rows[0]["userName"].ToString();
                Session["login"] = "true";
                Response.Redirect("seminar.aspx");
            }
            else
            {
                lblError.Text = "Username or password is not valid!";
                Panel1.Visible = true;
            }
        }
    }
}
